import { Request, Response } from 'express'
import { groupingService } from '../services/groupingService'

export const getGroupingState = async (_req: Request, res: Response) => {
  try {
    const state = groupingService.getGroupingState()
    res.json({
      success: true,
      data: state,
      message: '获取分组状态成功'
    })
  } catch (error) {
    console.error('获取分组状态失败:', error)
    res.status(500).json({
      success: false,
      message: '获取分组状态失败'
    })
  }
}

export const resetGroups = async (_req: Request, res: Response) => {
  try {
    // 重置分组状态
    groupingService.updateGroups(Array.from({ length: 8 }, () => ({ players: [] })))
    
    res.json({
      success: true,
      message: '分组重置成功'
    })
  } catch (error) {
    console.error('重置分组失败:', error)
    res.status(500).json({
      success: false,
      message: '重置分组失败'
    })
  }
}
